//
// Created by 17775 on 2024/11/21.
//

#ifndef RAYCI_BEAM_LINE_VIEW_H
#define RAYCI_BEAM_LINE_VIEW_H

#include <QDockWidget>
#include "../Common/common_2dview.h"
#include "../Common/commonchart.h"
#include "../Common/common_chart_options.h"
#include "beam_line_result.h"
#include "../RayCi/Beam_Line.h"


QT_BEGIN_NAMESPACE
namespace Ui { class Beam_Line_View; }
QT_END_NAMESPACE

class Beam_Line_View : public QDockWidget {
Q_OBJECT

signals:
    void sendAutoContrast(bool isAuto);
    void stopBeamLineThread();
    void reportBeamLine();
    void showBeamLine2DView();
    void BeamLineClicked();

public slots:
    void setAutoContrast();

public:
    explicit Beam_Line_View(QWidget *parent = nullptr);
    ~Beam_Line_View() override;

void mousePressEvent(QMouseEvent *event);

void setWindowTitleName(const QString& name);

    void setAuto(bool bAuto);
    void refreshChart();
    Common_2DView* getComm2DView() {
        return common2DView;
    }
    QList<CommonChart*> charts = {
            new CommonChart(this),  // YCrossChart
            new CommonChart(this),  // SummedIntensityChart
            new CommonChart(this),  // CenterChart
            new CommonChart(this),  // WidthChart
            new CommonChart(this),  // PeakIntensityChart
            new CommonChart(this),  // PeakPositionChart
    };
    QList<Common_Chart_Options*> options = {
            new Common_Chart_Options(this->parentWidget()),  // YCrossChartOptions
            new Common_Chart_Options(this->parentWidget()),  // SummedIntensityChartOptions
            new Common_Chart_Options(this->parentWidget()),  // CenterChartOptions
            new Common_Chart_Options(this->parentWidget()),  // WidthChartOptions
            new Common_Chart_Options(this->parentWidget()),  // PeakIntensityChartOptions
            new Common_Chart_Options(this->parentWidget()),  // PeakPositionChartChartOptions
    };
    void clearChart();
    void updateResult(BeamLineResult result);
    void hidePeakIntensity();
    void hidePeakPosition();

private:
    Ui::Beam_Line_View *ui;
    QWidget* menuPanel = nullptr;
    QWidget* lutPanel = nullptr;
    QVBoxLayout* menuLayout = nullptr;
    QVBoxLayout* lutLayout = nullptr;
    QWidget* centralWidget = nullptr;
    QHBoxLayout* mainLayout = nullptr;
    Common_2DView* common2DView = nullptr;
    QPushButton* btnSave = nullptr;
    QPushButton* btnGenerateSingle = nullptr;
    QPushButton* btn2DView = nullptr;
    QPushButton* btnYCrossSection = nullptr;
    QPushButton* btnLineResults = nullptr;
    QPushButton* btnSummedIntensityPreview = nullptr;
    QPushButton* btnCenterPreview = nullptr;
    QPushButton* btnWidthPreview = nullptr;
    QPushButton* btnPeakIntensityPreview = nullptr;
    QPushButton* btnPeakPositionPreview = nullptr;
    QPushButton* btnSelect = nullptr;
    QPushButton* btnReport = nullptr;
    QCheckBox* cBox_Auto = nullptr;
    QSplitter* mainSplitter = nullptr;
    QSplitter* topSplitter = nullptr;
    QSplitter* bottomSplitter = nullptr;

    Beam_Line_Result* beamLineResult = nullptr;

    bool _2DViewIsShow = true;
    bool YCrossViewIsShow = true;
    bool LineResultIsShow = true;
    bool summedIntensityIsHide = false;
    bool centerIsHide = false;
    bool widthIsHide = false;
    bool peakIntensityIsHide = false;
    bool peakPositionIsHide = false;
    void show2DView();
    void showYCrossView();
    void showLineResultView();
    void hideSummedIntensity();
    void hideCenter();
    void hideWidth();

    void closeEvent(QCloseEvent *event) override;
};


#endif //RAYCI_BEAM_LINE_VIEW_H
